package example.json.voice;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.dahantc.api.voice.json.HttpJSONClient;
import com.dahantc.api.voice.json.VoiceReqData;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

@Repository
public class DahanVoiceService {

	public String voice(String acc, String phones, String content){
		String result = "ok";
		try {
			HttpJSONClient client = new HttpJSONClient(dahan_master_url);

			List<VoiceReqData> list = new ArrayList<VoiceReqData>();

			for (String phone : phones.split(",")) {
				list.add(new VoiceReqData(phone, content, "", uuid(), 1, 0));
			}
			//list.add(new VoiceReqData("13812345678", "211457", "dh9876tishiyin", "", 1, 0));
			result = client.sendAuthCodeVoiceSms(dahan_acc, dahan_pwd, list);
			System.out.println(result);

			String reportResp = client.getVoiceReport(dahan_acc, dahan_pwd);

			System.out.println(reportResp);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static String uuid(){
		return UUID.randomUUID().toString().replace("-", ""); // 短信id，查询短信状态报告时需要，（可选）
	}

	@Value("${dahan.master.url}")
	private String dahan_master_url;

	@Value("${dahan.acc}")
	private String dahan_acc;

	@Value("${dahan.pwd}")
	private String dahan_pwd;
}
